//
//  RouterManager.swift
//  CandyDate
//
//  Created by zolobdz on 2017/9/26.
//  Copyright © 2017年 HeChao. All rights reserved.
//

import UIKit

typealias RouterParameter = [String : Any]
typealias CDSimpleClosure = ()->Void

enum ControllerName: String {
    //MARK: 登录注册
//    case loginRoot = "loginRoot" // 安装后第一次打开app展示的登录页
    case login = "loginSecond" //loginRoot页面点击登录后跳转的页面，切第二次以后打开app展示的登录页
//    case signupVerifyCode = "signupVerifyCode" // 注册-手机验证码
//    case signupSetPassword = "setupPassword" // 注册-设置密码
//    case signupUploadAvatar = "signupUploadAvatar" // 注册-设置头像
//    case signupUserInfo = "signupUserInfo" // 注册-填写用户个人信息
//    case signupVideoAuth = "signupVideoAuth" // 注册-视频认证
//    case authVideoRecord = "authVideoRecord" // 视频认证的拍摄
//    case forgetPassword = "forgetPassword" // 登录页忘记密码
    //MARK: 首页
//    case homepage = "homepage"
    //MARK: 消息
//    case messageList = "messageList"
//    case messageChat = "messageChat"
//    case messageSendLocation = "messageSendLocation"
//    case netCall = "NetCallViewController"
    
    //MARK: 通讯录
    
    //MARK: 我的
//    case me = "me"
//    case editMyInfo = "editMyInfo" // 编辑个人资料
//    case editHeight = "editHeight" // 编辑身高
//    case meBalance = "meBalance" // 我的-余额
//    case meBalanceDetail = "meBalanceDetail" // 我的-余额明细
//    case meCandyDate = "meCandyDate" // 我的-我的糖圈
//    case setting = "setting" // 我的-通用设置
//    case meVip = "myVip" // 我的-会员
    // 我的-设置
//    case accountSafety = "accountSafety" // 账号与安全
//    case newMessageSetting = "newMessageSetting" // 新消息设置
//    case privateSetting = "privateSetting" // 隐私设置
//    case aboutApp = "aboutApp" // 关于糖圈
//    case changePassword = "changePassword" // 登录用户修改密码
//    case settingAppNumberLock = "settingAppNumberLock" // 设置APP锁-数字密码
//    case editUserInfoItem = "editUserInfoItem" // 编辑用户信息的某项具体数值
//    case environmentConfig = "EnvironmentViewController" // 服务器环境配置页面
    
    //MARK: 用户
    //MARK: 条款
    //MARK: Presenet
    
}

enum RouterOpenType {
    case push
    case present
}

protocol RouterProtocol {
    func handle(parameter: RouterParameter?)
}

class RouterManager {

    static let shared = RouterManager()
    private init() {}
    
    func openPage(currentViewController: UIViewController,toVC: ControllerName,type: RouterOpenType = .push,parameter: RouterParameter? = nil,animated: Bool = true,closure: CDSimpleClosure? = nil){
        var destinationVC: UIViewController? = nil
        
//        switch toVC {
//        case .loginRoot:
//            destinationVC = LoginNavigationController()
//        case .login:
//            if currentViewController.navigationController is LoginNavigationController
//            {
//                destinationVC = LoginViewController()
//            }
//            else
//            {
//                let vc = LoginNavigationController()
//                vc.hidesBottomBarWhenPushed = true
//                vc.pushViewController(LoginViewController(), animated: animated)
//                destinationVC = vc
//            }
//        case .signupVerifyCode:
//            destinationVC = VerifyPhoneViewController()
//        case .signupSetPassword:
//            destinationVC = SetPasswordViewController()
//        case .homepage:
//            destinationVC = HomepageViewController()
//        case .messageList:
//            destinationVC = MessageListViewController()
//        case .contacts:
//            destinationVC = ContactsViewController()
//        case .me:
//            destinationVC = MeViewController()
//        case .messageChat:
//            destinationVC = MessageViewController()
//        case .signupUploadAvatar:
//            destinationVC = UploadAvatarViewController()
//        case .signupUserInfo:
//            destinationVC = SignupUserInfoViewController()
//        case .signupVideoAuth:
//            destinationVC = VideoAuthViewController()
//        case .authVideoRecord:
//            destinationVC = VideoOperationViewController()
//        case .forgetPassword:
//            destinationVC = ForgetPasswordViewController()
//        case .publishDateRules:
//            destinationVC = PublishDateRulesDetailViewController()
//        case .signupUserPrivateRules:
//            destinationVC = SignupRulesDetailViewController()
//        case .userInfo:
//            destinationVC = UserInfoViewController()
//        case .newFriend:
//            destinationVC = NewFriendsViewController()
//        case .inviteRecords:
//            destinationVC = InviteRecordsViewController()
//        case .editMyInfo:
//            destinationVC = EditMyInfoViewController()
//        case .userOperation:
//            destinationVC = UserMoreOperationViewController()
//        case .complaintUser:
//            destinationVC = ComplaintUserViewController()
//        case .editHeight:
//            destinationVC = EditHeightViewController()
//        case .meBalance:
//            destinationVC = BalanceViewController()
//        case .meCandyDate:
//            destinationVC = MyCandyDateViewController()
//        case .setting:
//            destinationVC = SettingViewController()
//        case .accountSafety:
//            destinationVC = AccountSafetyViewController()
//        case .newMessageSetting:
//            destinationVC = NewMessageSettingViewController()
//        case .privateSetting:
//            destinationVC = PrivateSettingViewController()
//        case .aboutApp:
//
//            destinationVC = AboutAppViewController()
//        case .changePassword:
//            destinationVC = ChangePasswordViewController()
//        case .settingAppNumberLock:
//            if type == .present
//            {
//                let settingNumberPasswordViewController = SettingNumberPasswordViewController()
//                destinationVC = MeNavigationController(rootViewController: settingNumberPasswordViewController)
//            }
//            else
//            {
//                destinationVC = SettingNumberPasswordViewController()
//            }
//        case .meBalanceDetail:
//            destinationVC = BalanceDetailViewController()
//        case .editUserInfoItem:
//            destinationVC = EditMeItemViewController()
//        case .messageSendLocation:
//            destinationVC = MessageChoosePOIViewController()
//        case .netCall:
//            destinationVC = NetCallViewController()
//        case .environmentConfig:
//            destinationVC = EnvironmentViewController()
//        case .meVip:
//            destinationVC = ChargeVipViewController()
//        case .villainVipCharge:
//            destinationVC = PresentNavigationController(rootViewController: ChargeVipViewController())
//        }
        
        guard let viewController = destinationVC else {
            return
        }
        
        // 传值1
        if viewController is BaseViewController  {
            (viewController as! BaseViewController).simpleClosure = closure
            (viewController as! BaseViewController).handle(parameter: parameter)
        }
        // 传值2
        if viewController is BaseNavigationController  {
            if let root = (viewController as! BaseNavigationController).topViewController as? BaseViewController
            {
                root.simpleClosure = closure
                root.handle(parameter: parameter)
            }
        }
            
        
        switch type {
        case .push:
            viewController.hidesBottomBarWhenPushed = true
            currentViewController.navigationController?.pushViewController(viewController, animated: animated)
        case .present:
            currentViewController.present(viewController, animated: animated, completion: nil)
        }
    }
}




